"""
FileName：assert_util.py
Description：
Author：gaojiahui
Time：2025/8/18 20:11
Website：https://gitee.com/gao-jiahui
"""
def assert_status_code(response, expected_code):
    """断言响应状态码"""
    assert response.status_code == expected_code,\
        f"期望状态码: {expected_code}, 实际状态码: {response.status_code}\n响应内容: {response.text}"

def assert_response_contains(response, expected_text):
    """断言响应包含文本"""
    assert expected_text in response.text,\
        f"响应中未找到文本: {expected_text}\n响应内容: {response.text}"

def assert_json_key_exists(data, key):
    """断言JSON数据中存在指定键"""
    assert key in data, f"响应中缺少必要字段: {key}"
    assert data[key] is not None, f"字段 {key} 的值不应为null"

def assert_json_value(response, key, expected_value):
    """断言JSON响应中键的值"""
    json_data = response.json()
    assert key in json_data, f"响应JSON中未找到键: {key}"
    actual_value = json_data[key]
    assert actual_value == expected_value,\
        f"键 '{key}' 的值不匹配，期望: {expected_value}, 实际: {actual_value}"